var gulp = require('gulp');
//Plugins模块获取
var minifycss = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var htmlmin = require('gulp-htmlmin');
var htmlclean = require('gulp-htmlclean');

var rename = require('gulp-rename');
var imagemin = require('gulp-imagemin');

// 压缩 public 目录 css文件
gulp.task('minify-css', function() {
  return gulp.src('./public/**/*.css')
  .pipe(minifycss())
  .pipe(gulp.dest('./public'));
});

// 压缩 public 目录 html文件
gulp.task('minify-html', function() {
  return gulp.src('./public/**/*.html')
  .pipe(htmlclean())
  .pipe(htmlmin({
    removeComments: true,
    minifyJS: true,
    minifyCSS: true,
    minifyURLs: true,
  }))
  .pipe(gulp.dest('./public'))
});

// 压缩 public/js 目录 js文件
gulp.task('minify-js', function() {
  return gulp.src('./public/**/*.js')
  .pipe(uglify())
  .pipe(gulp.dest('./public'));
});

//图片压缩
gulp.task('images', function() {
  gulp.src('./public/img/*.*')
  .pipe(imagemin({
    progressive: false
  }))
  .pipe(gulp.dest('././public/img/'));
});
// 执行 gulp 命令时执行的任务
gulp.task('default', [
  'minify-html', 'minify-css', 'minify-js'
]);
